package cn.ncucode.blog.tools;

import java.util.Date;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

public class EmailServ {

	String sslSmtPort = "25";
	String hostName = "smtp.163.com";
	String userName = "yeshacode@163.com";
	String password = "NZHGJSQFCBBLCNVZ";
	String from = userName;
	// String from = "yeshacode@163.com";
	String charset = "UTF-8";
	boolean debug = true;

	public static void main(String[] args) {

		System.out.println("x");

		Long a = new Date().getTime();
		System.out.println((a / 1000 / 60 / 60) % 24);

		// System.out.println(date2.getTime() - date1.getTime());

		// try {
		// // new EmailServ(true).sentEmail("359176485@qq.com", "测试", "发送邮件");
		// } catch (EmailException e) {

		// e.printStackTrace();
		// }
	}

	public EmailServ(boolean debug) {
		this.debug = debug;
	}

	public void sentEmail(String email, String title, String text) throws EmailException {
		if (debug) {
			return;
		}
		SimpleEmail mail = new SimpleEmail();
		mail.setSslSmtpPort(sslSmtPort);
		mail.setHostName(hostName);
		mail.setAuthentication(userName, password);
		mail.setFrom(from);
		String name = "临时用户";
		mail.addTo(email, name, charset);
		// 添加文本内容
		mail.setMsg(text);
		// 添加发送日期
		mail.setSentDate(new Date());
		// 添加邮件标题
		mail.setSubject(title);
		// 发送邮件
		mail.send();
	}
}